<template>
	<view>
		<button @click="downloadFIle()">下载文件</button>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				img:""
			}
		},
		methods: {
			downloadFIle() {
				const imgTask = uni.downloadFile({
					url:'https://cdn.pixabay.com/photo/2025/11/05/20/57/monastery-9939590_1280.jpg',
					success: (res) => {
						if(res.statusCode===200) {
							console.log("下载成功");
							uni.previewImage({
								urls:[res.tempFilePath]
							});
							this.img=res.tempFilePath;
						}
					},
					fail: (eMsg) => {
						console.log("下载失败:"+eMsg);
					}
				});
				imgTask.onProgressUpdate((res) => {
					console.log("下载进度:"+res.progress+"%");
					console.log("已下载:"+res.totalBytesWritten);
					console.log("总大小",res.totalBytesExpectedToWrite);
				})
			}
		}
	}
</script>

<style>

</style>
